capture log close
log using suic-econ-figure3.txt, replace text

// program:	suic-econ-figure3.do
// task:	plot estimates for demographic groups
// input:	estimates from poisson regressions
// output:	figure 3
// project: economic conditions and suicide
// author:  sam harper \ 17dec2014

//  #0
//  program setup

version 13
set linesize 80
clear all
macro drop _all


// #1 overall effect
tempfile gte
use te_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="1980-2010"
gen bygroup="Overall"
save `gte', replace


// #2
// By recessionary period
* during national recession
tempfile gnrec1
use recper, clear
keep if parm=="1.recper"
gen period="1980-2010"
gen agerange="15+"
gen category="Recessionary period"
gen bygroup="During national recession (2250 state-months)"
save `gnrec1'

* national recession
tempfile gnrec0
use recper, clear
keep if parm=="0.recper"
gen period="1980-2010"
gen agerange="15+"
gen category="Recessionary period"
gen bygroup="Absent national recession (16350 state-months)"
save `gnrec0'

* during state recession
tempfile strec1
use strec, clear
keep if parm=="2._at"
gen period="1980-2010"
gen agerange="15+"
gen category="Recessionary period"
gen bygroup="During state recession (4126 state-months)"
save `strec1'

* national recession
tempfile strec0
use strec, clear
keep if parm=="1._at"
gen period="1980-2010"
gen agerange="15+"
gen category="Recessionary period"
gen bygroup="Absent state recession (14474 state-months)"
save `strec0'

// #3
// Gender

* men
tempfile gmen
use sex_1_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="Gender"
gen bygroup="Men"
save `gmen', replace

* women
tempfile gwomen
use sex_2_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="Gender"
gen bygroup="Women"
save `gwomen', replace

// #4
// Race

* white
tempfile gwhite
use race2_1_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="Race"
gen bygroup="White"
save `gwhite', replace

* non-white
tempfile gnonwhite
use race2_2_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="Race"
gen bygroup="Non-white"
save `gnonwhite', replace


// #5
// Age groups

* 15-24
tempfile gage1
use agecat_1_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="Age"
gen bygroup="15-24 years"
save `gage1', replace

* 25-44
tempfile gage2
use agecat_2_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="Age"
gen bygroup="25-44 years"
save `gage2', replace

* 45-64
tempfile gage3
use agecat_3_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="Age"
gen bygroup="45-64 years"
save `gage3', replace

* 65+
tempfile gage4
use agecat_4_m_2, clear
keep if parm=="icei"
gen period="1980-2010"
gen agerange="15+"
gen category="Age"
gen bygroup="65 years and over"
save `gage4', replace

// #6
//  1994-2010 Education among those ages 25+

* All groups
tempfile te1994 
use te_1994__m_2, clear
keep if parm=="icei"
gen period="1994-2010"
gen agerange="25+"
gen category="1994-2010"
gen bygroup="Overall"
save `te1994', replace

* <12 years
tempfile geduc1
use educa3_1_m_2, clear
keep if parm=="icei"
gen period="1994-2010"
gen agerange="25+"
gen category="Education: ages 25+"
gen bygroup="<12 years"
save `geduc1', replace

* 12 years
tempfile geduc2
use educa3_2_m_2, clear
keep if parm=="icei"
gen period="1994-2010"
gen agerange="25+"
gen category="Education: ages 25+"
gen bygroup="12 years"
save `geduc2', replace

* >12 years
tempfile geduc3
use educa3_3_m_2, clear
keep if parm=="icei"
gen period="1994-2010"
gen agerange="25+"
gen category="Education: ages 25+"
gen bygroup=">12 years"
save `geduc3', replace

// #7 
// 1994-2010 Education among those ages 25-64

* <12 years
tempfile geduc1r
use educa3wa_1_m_2, clear
keep if parm=="icei"
gen period="1994-2010"
gen agerange="25-64"
gen category="Education: ages 25-64"
gen bygroup="<12 years"
save `geduc1r', replace

* 12 years
tempfile geduc2r
use educa3wa_2_m_2, clear
keep if parm=="icei"
gen period="1994-2010"
gen agerange="25-64"
gen category="Education: ages 25-64"
gen bygroup="12 years"
save `geduc2r', replace

* >12 years
tempfile geduc3r
use educa3wa_3_m_2, clear
keep if parm=="icei"
gen period="1994-2010"
gen agerange="25-64"
gen category="Education: ages 25-64"
gen bygroup=">12 years"
save `geduc3r', replace

// #8
// plot using -metan

use `gte', clear
append using `gnrec1' `gnrec0' `strec1' `strec0' `gmen' `gwomen' `gwhite' ///
	`gnonwhite' `gage1' `gage2' `gage3' `te1994' `gage4' `gtoteduc' ///
	`geduc1' `geduc2' `geduc3' `geduc1r' `geduc2r' `geduc3r' 

label var agerange "Age range"
label var period "Time"
label var category "Demographic category"
label var bygroup "Population"

qui metan estimate min95 max95, by(category) xlabel(-2, 0, 2)

* heterogeneity tests
metan estimate min95 max95, by(category) nograph fixedi

* graph

metan estimate min95 max95, by(category) nosubgroup  nooverall ///
	label(namevar=bygroup) rcols(agerange) lcols(bygroup) texts(115) ///
	effect("Rate Diff per 100000") nobox ///
	favours(Exposure decreases suicide # Exposure increases suicide) ///
	graphregion(fcolor(white) lcolor(white)) ///
	pointopt(msymbol(circle) mcolor(black) mfcolor(gray)) ///
	xlabel(-1.5,-1.0,-0.5,0,0.5,1.0,1.5) xsize(6.5) ysize(7)

log close
exit
